from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp

class PunchEntity(db.Model):
    employee = db.UserProperty()
    punch_date = db.DateTimeProperty(auto_now_add=True)
    hours = db.FloatProperty()
    project = db.StringProperty(choices=set(['State Quiz - UNIX', 'State Quiz - Web', 'Punchcard', 'Elephant Notes', 'Corporate Administration', 'Corporate Strategy and Planning', 'Other']))
    summary = db.TextProperty()

class Punch(webapp.RequestHandler):
# A very simple html form for browsers. No client programs (like AJAX)
# will invoke a "get" method at this URL.
    def get(self):
        self.response.headers['Content-Type']= 'text/html'
        self.response.out.write("""
          <html>
            <body>
                <form action="/punch" method="post">
                  Project: <br /><select name="project">
                  <option value="State Quiz - Web">State Quiz - Web</option>
                  <option value="State Quiz - UNIX">State Quiz - UNIX</option>
                  <option value="Punchcard">Punchcard</option>
                  <option value="Elephant Notes">Elephant Notes</option>
                  <option value="Corporate Administration">Corporate Administration></option>
                  <option value="Corporate Strategy and Planning">Corporate Strategy and Planning</option>
                  <option value="Other">Other</option>
                  </select><br /><br />
                  
                  Hours: <br /><input type="text" name="hours" maxlength="500" /><br /><br />
                  Summary: <br/><textarea name="summary" rows="4" cols="40"></textarea><br /><br /></div>
                  <input type="submit" value="Punch!" />
                </form>
            </body>
          </html>""")
# This Post method can be used by anything 
# i.e. http://mydomain.com/punch?project=Punchcard&hours=4.5&summary=Added+web+interface.
    def post(self):
        punch_entity = PunchEntity()
        punch_entity.employee = users.get_current_user()
        punch_entity.hours = float(self.request.get('hours'))
        punch_entity.project = self.request.get('project')
        punch_entity.summary = self.request.get('summary')
        punch_entity.put()
        self.response.out.write('PunchEntity created')
        self.redirect("/view_html")
